package com.core.dao;

import java.util.Date;

import org.springframework.stereotype.Repository;

import com.core.base.dao.BaseHibernateDao;
import com.core.model.RoleRank;

/**
 * 角色等级DAO
 * 
 * @author pt-chenqw
 *
 */
@Repository("roleRankDAO")
public class RoleRankDAO extends BaseHibernateDao<RoleRank> {
	
	/**
	 * 查询角色等级信息
	 * @param id
	 * @return
	 */
	public RoleRank getRoleRankByID(Integer id){
		String hql = "from RoleRank where id = ?";
		return findOne(hql, id);
	}
	
	/**
	 * 新增角色等级
	 * @param roleRank
	 */
	public void addRoleRank(RoleRank roleRank){
		roleRank.setCreatetime(new Date());
		roleRank.setUpdatetime(new Date());
		save(roleRank);
	}
	
	/**
	 * 更新角色等级信息
	 * @param roleRank
	 */
	public void updateRoleRankInfo(RoleRank roleRank){
		RoleRank rank = getRoleRankByID(roleRank.getId());
		rank.setRoleRankCode(roleRank.getRoleRankCode());
		rank.setRoleRankName(roleRank.getRoleRankName());
		rank.setCategoryID(roleRank.getCategoryID());
		rank.setStatus(roleRank.getStatus());
		rank.setUpdatetime(new Date());
		update(rank);
	}
	
	/**
	 * 删除角色等级信息
	 * @param id
	 */
	public void deleteRoleRank(Integer id){
		RoleRank roleRank = getRoleRankByID(id);
		delete(roleRank);
	}
	
	/**
	 * 根据code查询角色等级信息
	 * @param code
	 * @return
	 */
	public RoleRank getRoleRankByCode(String code){
		String hql = "from RoleRank where roleRankCode = ?";
		return findOne(hql, code);
	}

}
